//
//  HXFundTransferDataView.m
//  HXJBP
//
//  Created by zhangjingle on 13-12-13.
//  Copyright (c) 2013年 zhang jingle. All rights reserved.
//

#import "HXFundTransferDataView.h"
#import "HXAutoSizeLabel.h"
#define padding 5
#define paddingLeft 11
#define paddingRight 17
@interface HXFundTransferDataView()
{
    HXAutoSizeLabel * _fundName;
    HXAutoSizeLabel * _fundCode;
    HXAutoSizeLabel * _fundDate;
    HXAutoSizeLabel * _fundValue;
    HXAutoSizeLabel * _fundRaise;
    HXAutoSizeLabel * _fundNavShowLabel;
    HXAutoSizeLabel * _fundRaiseShowLabel;
}

//@property (nonatomic, retain) IBOutlet UILabel * fundName;
//@property (nonatomic, retain) IBOutlet UILabel * fundCode;
//@property (nonatomic, retain) IBOutlet UILabel * fundDate;
//@property (nonatomic, retain) IBOutlet UILabel * fundValue;
//@property (nonatomic, retain) IBOutlet UILabel * fundRaise;
//@property (nonatomic, retain) IBOutlet UILabel * fundNavShowLabel;
//@property (nonatomic, retain) IBOutlet UILabel * fundRaiseShowLabel;

//@property (nonatomic, retain) UIView * fundView;
@end

@implementation HXFundTransferDataView
-(void)dealloc
{
    [super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupFundView];
    }
    return self;
}

-(void)setupFundView
{
    CGRect bgImageRect = CGRectMake(5, 0, 310, 82);
    CGRect lineRect = CGRectMake(10, 41, 300, 1);
    
    CGRect fundNameRect = CGRectMake(11, 6, 111, 30);
    CGRect fundCodeRect = CGRectMake(130, 6, 74, 30);
    
    CGRect fundDateRect = CGRectMake(207, 6, 96, 30);
    
    CGRect fundRaiseShowLabelRect = CGRectMake(11, 45, 111, 35);
    CGRect fundRaiseRect = CGRectMake(130, 45, 61, 35);
    
    CGRect fundNavShowLabelRect = CGRectMake(193, 45, 60, 35);
    CGRect fundValueRect = CGRectMake(258, 45, 52, 35);
    
    UIFont * fontBold15 = [UIFont boldSystemFontOfSize:15];
    UIFont * font15 = [UIFont systemFontOfSize:15];
    
    UIColor * darkColor = [UIColor darkTextColor];
    UIColor * mfRed = RGB(195, 0, 4);
    UIColor * mfGray = RGB(140, 133, 133);
    
    UIImageView * _bgImageView = [[UIImageView alloc] initWithFrame:bgImageRect];
    UIImageView * _line = [[UIImageView alloc] initWithFrame:lineRect];
    _bgImageView.image = [UIImage imageNamed:@"book_bg.png"];
    _line.image = [UIImage imageNamed:@"form_split_line.png"];
    
    _fundName = [[HXAutoSizeLabel alloc] initWithFrame:fundNameRect];
    _fundCode = [[HXAutoSizeLabel alloc] initWithFrame:fundCodeRect];
    _fundDate = [[HXAutoSizeLabel alloc] initWithFrame:fundDateRect];
    _fundRaiseShowLabel = [[HXAutoSizeLabel alloc] initWithFrame:fundRaiseShowLabelRect];
    _fundRaise = [[HXAutoSizeLabel alloc] initWithFrame:fundRaiseRect];
    _fundNavShowLabel = [[HXAutoSizeLabel alloc] initWithFrame:fundNavShowLabelRect];
    _fundValue = [[HXAutoSizeLabel alloc] initWithFrame:fundValueRect];
    
    [_fundName setFont:fontBold15];
    [_fundCode setFont:fontBold15];
    [_fundDate setFont:font15];
    [_fundRaiseShowLabel setFont:font15];
    [_fundRaise setFont:fontBold15];
    [_fundNavShowLabel setFont:font15];
    [_fundValue setFont:fontBold15];
    
    [_fundName setTextColor:darkColor];
    [_fundCode setTextColor:darkColor];
    [_fundDate setTextColor:mfGray];
    [_fundRaiseShowLabel setTextColor:mfGray];
    [_fundRaise setTextColor:mfRed];
    [_fundNavShowLabel setTextColor:mfGray];
    [_fundValue setTextColor:mfRed];
    
    [self addSubview:_bgImageView];
    [self addSubview:_line];
    [self addSubview:_fundName];
    [self addSubview:_fundCode];
    [self addSubview:_fundDate];
    [self addSubview:_fundRaiseShowLabel];
    [self addSubview:_fundRaise];
    [self addSubview:_fundNavShowLabel];
    [self addSubview:_fundValue];
    
    [_bgImageView release];
    [_line release];
    [_fundName release];
    [_fundCode release];
    [_fundDate release];
    [_fundRaiseShowLabel release];
    [_fundRaise release];
    [_fundNavShowLabel release];
    [_fundValue release];
    
    for (UILabel * label in self.subviews) {
        if ([label isKindOfClass:[UILabel class]]) {
            label.backgroundColor = [UIColor clearColor];
        }
    }
    
}
-(void)loadData:(HXFundTransferArrayModel *)data
{
    NSString * kEmpty = @"--";
    _fundName.text  = (data.fundName.length  > 0 && data.fundName) ?data.fundName :kEmpty;
    _fundCode.text  = (data.fundCode.length  > 0 && data.fundCode) ?[NSString stringWithFormat:@"(%@)",data.fundCode] :kEmpty;
    _fundDate.text  = (data.fundDate.length  > 0 && data.fundDate) ?data.fundDate :kEmpty;
    _fundValue.text = (data.fundNav.length   > 0 && data.fundNav)  ?data.fundNav  :kEmpty;
    _fundRaise.text = (data.fundRaise.length > 0 && data.fundRaise)?data.fundRaise:kEmpty;
    _fundNavShowLabel.text = (data.fundNavShowLabel.length > 0 && data.fundNavShowLabel)?data.fundNavShowLabel:@"净值";
    _fundRaiseShowLabel.text = (data.fundRaiseShowLabel.length > 0 && data.fundRaiseShowLabel)?data.fundRaiseShowLabel:@"涨跌幅(%)";
    
    [self rankView];
    
}
-(void)rankView
{
    _fundName.left   = self.left + paddingLeft;
    _fundCode.left   = _fundName.right + padding;
    _fundDate.right  = self.right - paddingRight;
    _fundValue.right  = self.right - paddingRight;
    _fundNavShowLabel.right = _fundValue.left - padding;
    _fundRaiseShowLabel.left = self.left + paddingLeft;
    _fundRaise.left = _fundRaiseShowLabel.right + padding;
    
    if (![_fundRaise.text isEqualToString:@"--"] && [_fundRaise.text hasPrefix:@"-"]) {
        [_fundRaise setTextColor:RGB(27, 129, 14)];
    }
}


@end
